package com.lly.tboc.zhouyi.vm

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.lly.tboc.zhouyi.db.ZhouyiDb
import com.lly.tboc.zhouyi.vo.Gua
import com.lly.tboc.zhouyi.vo.WenYan
import com.lly.tboc.zhouyi.vo.Yao
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class YaoViewModel @Inject constructor(val db: ZhouyiDb) : ViewModel() {
    var gua by mutableStateOf<Gua?>(null)
    var yaoes by mutableStateOf<List<Yao>>(emptyList())
    var wenYan by mutableStateOf<WenYan?>(null)
    fun load(guaId: Int) {
        viewModelScope.launch(Dispatchers.IO) {
            val guaDao = db.guaDao()
            gua = guaDao.get(guaId)
            yaoes = db.yaoDao().get(guaId)
            wenYan = guaDao.getWenYan(guaId)
        }
    }
}